package com.qf.controller;

import com.alibaba.fastjson.JSON;
import com.qf.pojo.req.CSeatDetailReq;
import com.qf.pojo.req.DSeatDetailReq;
import com.qf.pojo.req.TrainOrderAndOrderDetail;
import com.qf.pojo.resp.BaseResp;
import com.qf.service.XcOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(value = "生成火车订单,生成动车订单,查询火车未支付订单", tags = "生成火车订单,生成动车订单,查询火车未支付订单")
@RestController
@RequestMapping("/heorder")

public class XcOrderController {
    @Autowired
    XcOrderService xcOrderService;

    @ApiOperation("生成火车订单")
    @RequestMapping(value = "/generatecorder", method = RequestMethod.POST)
    public BaseResp generatecorder(@RequestBody Map map, HttpServletRequest request) {
        Object cSeatDetailReq2 = map.get("cSeatDetailReq");
        String s = JSON.toJSONString(cSeatDetailReq2);
        CSeatDetailReq cSeatDetailReq = JSON.parseObject(s, CSeatDetailReq.class);
        return xcOrderService.generatecorder(cSeatDetailReq, request);
    }
    @ApiOperation("生成动车几高铁订单订单")
    @RequestMapping(value = "/generatedorder", method = RequestMethod.POST)
    public BaseResp generatedorder(@RequestBody Map map, HttpServletRequest request) {
        Object cSeatDetailReq2 = map.get("dSeatDetailReq");
        String s = JSON.toJSONString(cSeatDetailReq2);
        DSeatDetailReq dSeatDetailReq = JSON.parseObject(s, DSeatDetailReq.class);
        return xcOrderService.generatedorder(dSeatDetailReq, request);
    }
    @ApiOperation("查询所有火车票,包括已支付")
    @RequestMapping(value = "/findOrderByUserIdAll", method = RequestMethod.POST)
    public BaseResp findOrderByUserIdAll(HttpServletRequest request) {
        return xcOrderService.findOrderByUserIdAll(request);
    }

    @ApiOperation("查询火车以及动车未支付的订单")
    @RequestMapping(value = "/findOrderByUserId", method = RequestMethod.POST)
    public BaseResp findOrderByUserId(HttpServletRequest request) {
        return xcOrderService.findOrderByUserId(request);
    }


    @ApiOperation("删除父订单以及子订单")
    @RequestMapping(value = "/deleteorder",method = RequestMethod.POST)
    public  BaseResp deleteorder(@RequestBody Map map, HttpServletRequest request){
        Object orderAndOrderDetail = map.get("OrderAndOrderDetail");
        String s = JSON.toJSONString(orderAndOrderDetail);
        TrainOrderAndOrderDetail trainOrderAndOrderDetail = JSON.parseObject(s, TrainOrderAndOrderDetail.class);
        return xcOrderService.deleteorder(trainOrderAndOrderDetail);
    }
}
